<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>发送邮件</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ezmlm-hash.html">« ezmlm_hash</a></li>
      <li style="float: right;"><a href="book.mailparse.html">Mailparse »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mail.html">Mail 函数</a></li>
    <li>发送邮件</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mail" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mail</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mail</span> &mdash; <span class="dc-title">发送邮件</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mail-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mail</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$to</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$subject</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$additional_headers</code><span class="initializer"> = []</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$additional_params</code><span class="initializer"> = &quot;&quot;</span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   发送一封电子邮件。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mail-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">to</code></dt>

     <dd>

      <p class="para">
       电子邮件收件人，或收件人列表。
      </p>
      <p class="para">
       本字符串的格式必须符合
       <a href="http://www.faqs.org/rfcs/rfc2822" class="link external">&raquo;&nbsp;RFC 2822</a>。例如：
       <ul class="simplelist">
        <li class="member">user@example.com</li>
        <li class="member">user@example.com, anotheruser@example.com</li>
        <li class="member">User &lt;user@example.com&gt;</li>
        <li class="member">User &lt;user@example.com&gt;, Another User &lt;anotheruser@example.com&gt;</li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">subject</code></dt>

     <dd>

      <p class="para">
       电子邮件的主题。
      </p>
      <div class="caution"><strong class="caution">警告</strong>
       <p class="para">
        本项不能包含任何换行符，否则邮件可能无法正确发送。
       </p>
      </div>
     </dd>

    
    
     <dt>
<code class="parameter">message</code></dt>

     <dd>

      <p class="para">
       所要发送的消息。
      </p>
      <p class="para">
       行之间必须以一个 CRLF（\r\n）分隔。每行不能超过 70 个字符。
      </p>
      <div class="caution"><strong class="caution">警告</strong>
       <p class="para">
        （Windows 下）当 PHP 直接连接到 SMTP 服务器时，如果在一行开头发现一个句号，则会被删掉。要避免此问题，将单个句号替换成两个句号。
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n."</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n.."</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

       </p>
      </div>
     </dd>

    
    
     <dt>
<code class="parameter">additional_headers</code>（可选项）</dt>

     <dd>

      <p class="para">
       <span class="type">String</span> or <span class="type">array</span> to be inserted at the end of the email header.
      </p>
      <p class="para">
       This is typically used to add extra headers (From, Cc, and Bcc).
       Multiple extra headers should be separated with a CRLF (\r\n).
       If outside data are used to compose this header, the data should be sanitized
       so that no unwanted headers could be injected. 
      </p>
      <p class="para">
       If an <span class="type">array</span> is passed, its keys are the header names and its
       values are the respective header values.
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        Before PHP 5.4.42 and 5.5.27, repectively, <code class="parameter">additional_headers</code> did not have mail header
        injection protection. Therefore, users must make sure specified headers
        are safe and contains headers only. i.e. Never start mail body by putting
        multiple newlines.
       </p>
      </p></blockquote>      
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        When sending mail, the mail <em class="emphasis">must</em> contain
        a <code class="literal">From</code> header. This can be set with the
        <code class="parameter">additional_headers</code> parameter, or a default
        can be set in <var class="filename">php.ini</var>.
       </p>
       <p class="para">
        Failing to do this will result in an error
        message similar to <code class="literal">Warning: mail(): &quot;sendmail_from&quot; not
        set in php.ini or custom &quot;From:&quot; header missing</code>.
        The <code class="literal">From</code> header sets also
        <code class="literal">Return-Path</code> when sending directly via SMTP (Windows only).
       </p>
      </p></blockquote>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        If messages are not received, try using a LF (\n) only.
        Some Unix mail transfer agents (most notably
        <a href="http://cr.yp.to/qmail.html" class="link external">&raquo;&nbsp;qmail</a>) replace LF by CRLF
        automatically (which leads to doubling CR if CRLF is used).
        This should be a last resort, as it does not comply with
        <a href="http://www.faqs.org/rfcs/rfc2822" class="link external">&raquo;&nbsp;RFC 2822</a>.
       </p>
      </p></blockquote>
     </dd>

    
    
     <dt>
<code class="parameter">additional_params</code> (optional)</dt>

     <dd>

      <p class="para">
       The <code class="parameter">additional_params</code> parameter
       can be used to pass additional flags as command line options to the
       program configured to be used when sending mail, as defined by the
       <code class="literal">sendmail_path</code> configuration setting. For example,
       this can be used to set the envelope sender address when using
       sendmail with the <code class="literal">-f</code> sendmail option.
      </p>
      <p class="para">
       This parameter is escaped by <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span> internally
       to prevent command execution. <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span> prevents
       command execution, but allows to add additional parameters. For security reasons,
       it is recommended for the user to sanitize this parameter to avoid adding unwanted
       parameters to the shell command.
      </p>
      <p class="para">
       Since <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span> is applied automatically, some characters
       that are allowed as email addresses by internet RFCs cannot be used. 
       <span class="function"><strong>mail()</strong></span> can not allow such characters, so in programs where the use of
       such characters is required, alternative means of sending emails (such as using a framework
       or a library) is recommended. 
      </p>
      <p class="para">
       The user that the webserver runs as should be added as a trusted user to the
       sendmail configuration to prevent a &#039;X-Warning&#039; header from being added
       to the message when the envelope sender (-f) is set using this method.
       For sendmail users, this file is <var class="filename">/etc/mail/trusted-users</var>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mail-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果邮件成功接受投递，返回 <strong><code>true</code></strong>，否则返回 <strong><code>false</code></strong>。
  </p>
  <p class="para">
   同样重要的是要注意到，邮件仅接受了投递并不意味着邮件实际上达到预定目的地。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mail-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.2.0</td>
       <td>
        现在 <code class="parameter">additional_headers</code> 参数开始支持 <span class="type">array</span>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mail-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3012">
    <p><strong>示例 #1 发送邮件</strong></p>
    <div class="example-contents"><p>
     使用 <span class="function"><strong>mail()</strong></span> 发送简单的邮件：
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;消息<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Line&nbsp;1\r\nLine&nbsp;2\r\nLine&nbsp;3"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;如果任何一行超过&nbsp;70&nbsp;个字符，应该使用&nbsp;wordwrap()<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$message</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">70</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\r\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;发送<br /></span><span style="color: #0000BB">mail</span><span style="color: #007700">(</span><span style="color: #DD0000">'caffeinated@example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'My&nbsp;Subject'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-3013">
    <p><strong>示例 #2 使用额外标头发送邮件</strong></p>
    <div class="example-contents"><p>
     The addition of basic headers, telling the MUA
     the From and Reply-To addresses:
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$to&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'nobody@example.com'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'the&nbsp;subject'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$headers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'From:&nbsp;webmaster@example.com'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\r\n"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'Reply-To:&nbsp;webmaster@example.com'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\r\n"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'X-Mailer:&nbsp;PHP/'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">phpversion</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">mail</span><span style="color: #007700">(</span><span style="color: #0000BB">$to</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$headers</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-3014">
    <p><strong>示例 #3 使用 <span class="type">array</span> 形式的额外标头发送邮件</strong></p>
    <div class="example-contents"><p>
     This example sends the same mail as the example immediately above, but
     passes the additional headers as array (available as of PHP 7.2.0).
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$to&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'nobody@example.com'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'the&nbsp;subject'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$headers&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'From'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'webmaster@example.com'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'Reply-To'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'webmaster@example.com'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'X-Mailer'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'PHP/'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">phpversion</span><span style="color: #007700">()<br />);<br /><br /></span><span style="color: #0000BB">mail</span><span style="color: #007700">(</span><span style="color: #0000BB">$to</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$headers</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-3015">
    <p><strong>示例 #4 Sending mail with an additional command line parameter.</strong></p>
    <div class="example-contents"><p>
     The <code class="parameter">additional_params</code> parameter
     can be used to pass an additional parameter to the program configured
     to use when sending mail using the <code class="literal">sendmail_path</code>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />mail</span><span style="color: #007700">(</span><span style="color: #DD0000">'nobody@example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'the&nbsp;subject'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'the&nbsp;message'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'-fwebmaster@example.com'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-3016">
    <p><strong>示例 #5 Sending HTML email</strong></p>
    <div class="example-contents"><p>
     It is also possible to send HTML email with <span class="function"><strong>mail()</strong></span>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Multiple&nbsp;recipients<br /></span><span style="color: #0000BB">$to&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'johny@example.com,&nbsp;sally@example.com'</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;note&nbsp;the&nbsp;comma<br /><br />//&nbsp;Subject<br /></span><span style="color: #0000BB">$subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Birthday&nbsp;Reminders&nbsp;for&nbsp;August'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Message<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'<br />&lt;html&gt;<br />&lt;head&gt;<br />&nbsp;&nbsp;&lt;title&gt;Birthday&nbsp;Reminders&nbsp;for&nbsp;August&lt;/title&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&nbsp;&nbsp;&lt;p&gt;Here&nbsp;are&nbsp;the&nbsp;birthdays&nbsp;upcoming&nbsp;in&nbsp;August!&lt;/p&gt;<br />&nbsp;&nbsp;&lt;table&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;Person&lt;/th&gt;&lt;th&gt;Day&lt;/th&gt;&lt;th&gt;Month&lt;/th&gt;&lt;th&gt;Year&lt;/th&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;Johny&lt;/td&gt;&lt;td&gt;10th&lt;/td&gt;&lt;td&gt;August&lt;/td&gt;&lt;td&gt;1970&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;Sally&lt;/td&gt;&lt;td&gt;17th&lt;/td&gt;&lt;td&gt;August&lt;/td&gt;&lt;td&gt;1973&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<br />&nbsp;&nbsp;&lt;/table&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br />'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;To&nbsp;send&nbsp;HTML&nbsp;mail,&nbsp;the&nbsp;Content-type&nbsp;header&nbsp;must&nbsp;be&nbsp;set<br /></span><span style="color: #0000BB">$headers</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">'MIME-Version:&nbsp;1.0'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$headers</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">'Content-type:&nbsp;text/html;&nbsp;charset=iso-8859-1'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Additional&nbsp;headers<br /></span><span style="color: #0000BB">$headers</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">'To:&nbsp;Mary&nbsp;&lt;mary@example.com&gt;,&nbsp;Kelly&nbsp;&lt;kelly@example.com&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$headers</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">'From:&nbsp;Birthday&nbsp;Reminder&nbsp;&lt;birthday@example.com&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$headers</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">'Cc:&nbsp;birthdayarchive@example.com'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$headers</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">'Bcc:&nbsp;birthdaycheck@example.com'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Mail&nbsp;it<br /></span><span style="color: #0000BB">mail</span><span style="color: #007700">(</span><span style="color: #0000BB">$to</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">"\r\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$headers</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     <blockquote class="note"><p><strong class="note">注意</strong>: 
      <p class="para">
       If intending to send HTML or otherwise Complex mails, it is recommended
       to use the PEAR package <a href="https://pear.php.net/package/Mail" class="link external">&raquo;&nbsp;PEAR::Mail</a>.
      </p>
     </p></blockquote>
    </p></div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mail-notes">    
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    The SMTP implementation (Windows only) of <span class="function"><strong>mail()</strong></span> differs in many
    ways from the sendmail implementation. First, it doesn&#039;t use a local binary
    for composing messages but only operates on direct sockets which means a
    <code class="literal">MTA</code> is needed listening on a network socket (which
    can either on the localhost or a remote machine).
   </p>
   <p class="para">
    Second, the custom headers like
    <code class="literal">From:</code>,
    <code class="literal">Cc:</code>,
    <code class="literal">Bcc:</code> and
    <code class="literal">Date:</code> are
    <em class="emphasis">not</em> interpreted by the
    <code class="literal">MTA</code> in the first place, but are parsed by PHP.
   </p>
   <p class="para">
    As such, the <code class="parameter">to</code> parameter should not be an address
    in the form of &quot;Something &lt;someone@example.com&gt;&quot;. The
    mail command may not parse this properly while talking with 
    the MTA.
   </p>
  </p></blockquote>
  
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    值得注意的是，<span class="function"><strong>mail()</strong></span> 不适合在循环中发送大量邮件。发送每封邮件，此函数为打开和关闭一个套接字，效率不高。
   </p>
   <p class="para">
    要发送大量邮件，请参阅
    <a href="https://pear.php.net/package/Mail" class="link external">&raquo;&nbsp;PEAR::Mail</a> 和
    <a href="https://pear.php.net/package/Mail_Queue" class="link external">&raquo;&nbsp;PEAR::Mail_Queue</a> 包。
   </p>
  </p></blockquote>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    以下 RFC 可能有用：
    <a href="http://www.faqs.org/rfcs/rfc1896" class="link external">&raquo;&nbsp;RFC 1896</a>、<a href="http://www.faqs.org/rfcs/rfc2045" class="link external">&raquo;&nbsp;RFC 2045</a>、
    <a href="http://www.faqs.org/rfcs/rfc2046" class="link external">&raquo;&nbsp;RFC 2046</a>、<a href="http://www.faqs.org/rfcs/rfc2047" class="link external">&raquo;&nbsp;RFC 2047</a>、
    <a href="http://www.faqs.org/rfcs/rfc2048" class="link external">&raquo;&nbsp;RFC 2048</a>、<a href="http://www.faqs.org/rfcs/rfc2049" class="link external">&raquo;&nbsp;RFC 2049</a> 和
    <a href="http://www.faqs.org/rfcs/rfc2822" class="link external">&raquo;&nbsp;RFC 2822</a>。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mail-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mb-send-mail.html" class="function" rel="rdfs-seeAlso">mb_send_mail()</a> - 发送编码过的邮件</span></li>
    <li class="member"><span class="function"><a href="function.imap-mail.html" class="function" rel="rdfs-seeAlso">imap_mail()</a> - Send an email message</span></li>
    <li class="member"><a href="https://pear.php.net/package/Mail" class="link external">&raquo;&nbsp;PEAR::Mail</a></li>
    <li class="member"><a href="https://pear.php.net/package/Mail_Mime" class="link external">&raquo;&nbsp;PEAR::Mail_Mime</a></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>